package com.gqb.Advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component("serviceAspect")
@Aspect
public class ServiceAspect {
	
	@Pointcut("execution(* com.gqb.Advice.GreetImpl.*(..))")
	public void aspect(){
		
	}
	
	@Before("aspect()")
	public void before() throws Exception{
		System.out.println("before");
		throw new Exception("抛出一个异常");
	}
	@After("aspect()")
	public void after(){
		System.out.println("after");
	}
	
	@AfterReturning("aspect()")
	public void afterR(){
		System.out.println("afterR");
	}
	@AfterThrowing(value="aspect()",throwing = "ex")
	public void afterThrow(JoinPoint joinPoint, Exception ex){
		System.out.println(ex.getMessage());
	}
}
